package cn.nexd.map.location.collector.bean;

import android.os.Parcel;
import android.os.Parcelable;

import org.json.JSONException;
import org.json.JSONStringer;

/**
 * SensorDataResult create by codingfish at 15/5/4
 * TODO:
 *
 * @Version V1.0
 */
public class SensorDataResult implements Parcelable {

    private String id;

    private float[] values;
    private int accuracy;
    private long timestamp;
    private String sensor;
    private int sensorType;
    private String sensorName;
    private String userId;


    public float[] getValues() {
        return values;
    }

    public void setValues(float[] values) {
        this.values = values;
    }

    public int getAccuracy() {
        return accuracy;
    }

    public void setAccuracy(int accuracy) {
        this.accuracy = accuracy;
    }

    public long getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(long timestamp) {
        this.timestamp = timestamp;
    }

    public String getSensor() {
        return sensor;
    }

    public void setSensor(String sensor) {
        this.sensor = sensor;
    }

    public int getSensorType() {
        return sensorType;
    }

    public void setSensorType(int sensorType) {
        this.sensorType = sensorType;
    }

    public String getSensorName() {
        return sensorName;
    }

    public void setSensorName(String sensorName) {
        this.sensorName = sensorName;
    }

    public static Creator<SensorDataResult> getCreator() {
        return CREATOR;
    }


    public SensorDataResult() {
    }

    public SensorDataResult(Parcel source) {

        id = source.readString();
        source.readFloatArray(values);
        accuracy = source.readInt();
        timestamp = source.readLong();
        sensor = source.readString();
        sensorType = source.readInt();
        sensorName = source.readString();
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(id);
        dest.writeFloatArray(values);
        dest.writeInt(accuracy);
        dest.writeLong(timestamp);
        dest.writeString(sensor);
        dest.writeInt(sensorType);
        dest.writeString(sensorName);
    }


    public static final Creator<SensorDataResult> CREATOR = new Creator<SensorDataResult>() {
        @Override
        public SensorDataResult createFromParcel(Parcel source) {
            return new SensorDataResult(source);
        }

        @Override
        public SensorDataResult[] newArray(int size) {
            return new SensorDataResult[size];
        }
    };

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public JSONStringer sensorValuesToString() {
//        StringBuilder stringBuilder = new StringBuilder();
        JSONStringer jsonStringer = new JSONStringer();

        try {
            jsonStringer.object();
            for (int i = 0, len = values.length; i < len; i++) {
                jsonStringer.value(values[i]);
            }
            jsonStringer.endObject();
        } catch (JSONException e) {
            e.printStackTrace();
        }
//        stringBuilder.append("[");
//        for (int i = 0, len = values.length; i < len; i++) {
//            stringBuilder.append(Float.toString(values[i]));
//            if (i < len - 1) {
//                stringBuilder.append(",");
//            }
//        }
//
//        stringBuilder.append("]");
        return jsonStringer;
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }
}
